function y = NearestCorners(pose,samples,num)

% num: number of nearest corners
Neibor = [];

for i=1:size(pose,2)
    
    flg = zeros(size(samples,2));
    idx = 0;
    for j=1:num
        dist = 1e6;
        for k=1:size(samples,2)
            if (dist > norm(pose(:,i)-samples(:,k)))&&(~flg(k)),
                dist = norm(pose(:,i)-samples(:,k));
%                 Neibor(:,j,i) = samples(:,k);
                Neibor(j,i) = k;
                idx = k;
            end
        end
        flg(idx) = 1;
    end
end

y = Neibor;
end